package com.zenq.ssm.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.zenq.ssm.entity.Category;
import com.zenq.ssm.mapper.CategoryMapper;

@Service
public class CategoryService {

	@Autowired
	private CategoryMapper categoryMapper;
	/**
	 * 查询所有分类
	 * @return
	 */
	public List<Category> getAllCategory() {
		return categoryMapper.selectAll();
	}
	
	/**
	 * 
	 * @param category 查询条件参数
	 * @param page 页码
	 * @param rows 每页显示记录条数
	 * @return
	 */
	public List<Category> getCategoryPage(Category category, int page, int rows) {
		//1. pageHelper的startPage
		PageHelper.startPage(page, rows);
		//2. 直接调用mapper中的查询方法进行查询
		return categoryMapper.selectByCondition(category);
	}
	
	
	/**
	 * 根据主键查询单个分类
	 * @param id
	 * @return
	 */
	public Category getById(int id) {
		return categoryMapper.selectByPrimaryKey(id);
	}
	/**
	 * 修改分类
	 * @param category
	 * @return
	 */
	public int updateCategory(Category category) {
		return categoryMapper.updateByPrimaryKey(category);
	}
}
